'''
https://leetcode.cn/problems/assign-cookies/description/
'''
import heapq
from typing import List


class Solution:
    def findContentChildren(self, g: List[int], s: List[int]) -> int:
        g.sort()
        s.sort()
        n = len(g)
        i = 0
        pq = []
        res = 0
        for size in s:
            while i < n and g[i] <= size:
                heapq.heappush(pq, -g[i])
                i += 1
            if pq:
                heapq.heappop(pq)
                res += 1
        return res